package com.genpact.ws;

import java.io.IOException;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(value = "/mywebsocket")
public class WebsocketTest {
	
	 @OnMessage
	  public void onMessage(String message, Session session)
	    throws IOException, InterruptedException {
	   
	    // Print the client message for testing purposes
	    System.out.println("Received: " + message);
	   
	    // Send the first message to the client
	    session.getBasicRemote().sendText("---------This is the first server message--------");
	    
	    session.getBasicRemote().sendText(message);
	    // Send a final message to the client
	    session.getBasicRemote().sendText("---------This is the last server message---------");
	  }
	   
	  @OnOpen
	  public void onOpen() {
	    System.out.println("Client connected");
	  }
	 
	  @OnClose
	  public void onClose() {
	    System.out.println("Connection closed");
	  }
}
